/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * 
 *
 * Created on 12/02/2008, 04:30:28 PM
 */
package org.pagos.comercios;


import org.comercios.registros.ComerciosBusquedaFrame;
import org.mybeans.Sesion;

import org.mybeans.ComerciosBeans;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.mybeans.TemporalInformesPagosMensualesBeans;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author avbravo
 */
public class ComerciosPagosVerFrame extends javax.swing.JFrame {

    Sesion sesion;
    String idComercio;
    int Anio;
    String  reportSource;
    ComerciosBeans comerciosBeans;
    TemporalInformesPagosMensualesBeans temporalInformesPagosMensualesBeans;
    DefaultTableModel modelo, modelo2;
    String sql;
    int fila = -1;
    int fila2 = -1;
    boolean focoComercio = false;

    public ComerciosPagosVerFrame() {
        initComponents();
        sesion = new Sesion();
        comerciosBeans = new ComerciosBeans();
        temporalInformesPagosMensualesBeans = new TemporalInformesPagosMensualesBeans();
        modelo = (DefaultTableModel) jXTableMes.getModel();
        modelo2 = (DefaultTableModel) jXTableAnual.getModel();

        /*
         * Fondo
         */

         
         
         

        jXPanel1.setOpaque(false);
        setContentPane(jXPanel1);
        /*
         * fondo
         */
        java.util.Calendar ca = java.util.Calendar.getInstance();
        java.sql.Date mydate = new java.sql.Date(ca.getTimeInMillis());
//        jFormattedTextFieldFecha.setValue(mydate);
        sesion.setTipoId("comercios");

        this.Anio = ca.get(java.util.Calendar.YEAR);
        jTextFieldAnio.setText(String.valueOf(this.Anio));

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldIdComercio = new javax.swing.JTextField();
        jTextFieldComercio = new javax.swing.JTextField();
        jButtonBuscar = new javax.swing.JButton();
        jButtonRegresar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldAnio = new javax.swing.JTextField();
        jButtonMostrar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTableMes = new org.jdesktop.swingx.JXTable();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTableAnual = new org.jdesktop.swingx.JXTable();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ver Pagos de Comercios");
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jLabel4.setText("Codigo");

        jLabel5.setText("Comercio");

        jTextFieldIdComercio.setColumns(35);
        jTextFieldIdComercio.setToolTipText("");
        jTextFieldIdComercio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldIdComercioControlActionPerformed(evt);
            }
        });
        jTextFieldIdComercio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldIdComercioKeyPressed(evt);
            }
        });

        jTextFieldComercio.setColumns(70);
        jTextFieldComercio.setEnabled(false);

        jButtonBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/search.png"))); // NOI18N
        jButtonBuscar.setToolTipText("Buscar");
        jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarActionPerformed(evt);
            }
        });

        jButtonRegresar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/regresar.jpeg"))); // NOI18N
        jButtonRegresar.setToolTipText("Regresar");
        jButtonRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonRegresarActionPerformed(evt);
            }
        });

        jLabel1.setText("Año");

        jTextFieldAnio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldAnioActionPerformed(evt);
            }
        });

        jButtonMostrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/tools.png"))); // NOI18N
        jButtonMostrar.setToolTipText("Procesar");
        jButtonMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMostrarActionPerformed(evt);
            }
        });

        jXTableMes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "año", "regimen", "codigo", "ene", "feb", "mar", "abr", "may", "jun", "jul", "ago", "sep", "oct", "nov", "dic"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false, false, false, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jXTableMes);
        jXTableMes.getColumnModel().getColumn(6).setResizable(false);

        jTabbedPane1.addTab("Mensuales", jScrollPane1);

        jXTableAnual.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "año", "regimen", "codigo", "recibo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(jXTableAnual);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 754, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 2, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 750, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 2, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 277, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(0, 3, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 3, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Anuales", jPanel1);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gif/preview.png"))); // NOI18N
        jButton1.setToolTipText("Imprimir tarjeta de pagos");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldIdComercio, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(38, 38, 38)
                        .addComponent(jButtonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(32, 32, 32)
                        .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jButtonMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldComercio, javax.swing.GroupLayout.PREFERRED_SIZE, 341, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 758, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jTextFieldIdComercio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButtonBuscar)
                    .addComponent(jButtonRegresar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldComercio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addGroup(jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextFieldAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jXPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(45, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldIdComercioControlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldIdComercioControlActionPerformed

        ValidarComercios();

    }//GEN-LAST:event_jTextFieldIdComercioControlActionPerformed

    private void ValidarComercios() {
        try {
            LimpiarTable();


            this.idComercio = this.jTextFieldIdComercio.getText();
            sesion.setIdComercio(this.jTextFieldIdComercio.getText());
            comerciosBeans.setIdComercio(idComercio);
            if (comerciosBeans.Consultar() == true) {
                CargarComercios();
                CargarImpuestos();
            }

        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ComerciosPagosVerFrame.java\njTextFieldIdComercioControlActionPerformed()\n" + ex.getMessage().toString());
        }
    }
    private void jTextFieldIdComercioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldIdComercioKeyPressed
}//GEN-LAST:event_jTextFieldIdComercioKeyPressed

    private void jButtonBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarActionPerformed

        ComerciosBusquedaFrame comerciosBusquedaFrame = new ComerciosBusquedaFrame();
        comerciosBusquedaFrame.setLocationRelativeTo(null);
        comerciosBusquedaFrame.setVisible(true);
        focoComercio = true;
}//GEN-LAST:event_jButtonBuscarActionPerformed

    private void jButtonRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegresarActionPerformed

        this.dispose();
}//GEN-LAST:event_jButtonRegresarActionPerformed

    private void jButtonMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMostrarActionPerformed
        // TODO add your handling code here:
        try {
            CargarComercios();
            LimpiarTable();
            CargarImpuestos();
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ComerciosPagosVerFrame.java\njButtonMostrarActionPerformed()\n" + ex.getMessage().toString());
        }
}//GEN-LAST:event_jButtonMostrarActionPerformed

    private void jTextFieldAnioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldAnioActionPerformed
        // TODO add your handling code here:
        try {
            CargarComercios();
            LimpiarTable();
            CargarImpuestos();
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "ComerciosPagosVerFrame.java\njTextFieldAnioActionPerformed()\n" + ex.getMessage().toString());
        }
    }//GEN-LAST:event_jTextFieldAnioActionPerformed

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
        try {

            if (focoComercio) {
                CargarComercios();
                LimpiarTable();
                CargarImpuestos();
            }

            focoComercio = false;
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Clase: PagosComerciosEventualesFrame.java\nBoton Actualizar Impuestos()\n " + ex.getMessage().toString());
        }
    }//GEN-LAST:event_formWindowGainedFocus

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
         try {
            temporalInformesPagosMensualesBeans.LimpiarTemporal();
            int n = jXTableMes.getRowCount();
            int nanual =jXTableAnual.getRowCount();
            if (n == -1 && nanual == -1) {
                JOptionPane.showMessageDialog(this, "No hay registros de pagos", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            for (int i = 0; i < n; i++) {
                //this.idRegimen = String.valueOf(jXTable1.getValueAt(i, 1));
                String tmp;
                tmp = String.valueOf(jXTableMes.getValueAt(i, 1));
                if (tmp != null) {
                    temporalInformesPagosMensualesBeans.setRegimen(tmp);
                }
                tmp = String.valueOf(jXTableMes.getValueAt(i, 2));
                if (tmp != null) {
                    temporalInformesPagosMensualesBeans.setIdRegimen(tmp);
                }

//enero
                temporalInformesPagosMensualesBeans.setEnero(String.valueOf(jXTableMes.getValueAt(i, 3)));
                temporalInformesPagosMensualesBeans.setFebrero(String.valueOf(jXTableMes.getValueAt(i, 4)));
                temporalInformesPagosMensualesBeans.setMarzo( String.valueOf(jXTableMes.getValueAt(i, 5)));
                temporalInformesPagosMensualesBeans.setAbril( String.valueOf(jXTableMes.getValueAt(i, 6)));
                temporalInformesPagosMensualesBeans.setMayo( String.valueOf(jXTableMes.getValueAt(i, 7)));
                temporalInformesPagosMensualesBeans.setJunio( String.valueOf(jXTableMes.getValueAt(i, 8)));
                temporalInformesPagosMensualesBeans.setJulio( String.valueOf(jXTableMes.getValueAt(i, 9)));
                temporalInformesPagosMensualesBeans.setAgosto(String.valueOf(jXTableMes.getValueAt(i, 10)));
                temporalInformesPagosMensualesBeans.setSeptiembre(String.valueOf(jXTableMes.getValueAt(i, 11)));
                temporalInformesPagosMensualesBeans.setOctubre(String.valueOf(jXTableMes.getValueAt(i, 12)));
                temporalInformesPagosMensualesBeans.setNoviembre(String.valueOf(jXTableMes.getValueAt(i, 13)));
                temporalInformesPagosMensualesBeans.setDiciembre( String.valueOf(jXTableMes.getValueAt(i, 14)));
                tmp = jTextFieldIdComercio.getText();

                temporalInformesPagosMensualesBeans.setId(tmp);

                temporalInformesPagosMensualesBeans.setTipoId("comercios");
                tmp = jTextFieldComercio.getText();
                temporalInformesPagosMensualesBeans.setPropietario(tmp);
                temporalInformesPagosMensualesBeans.setPeriodopago("");
                temporalInformesPagosMensualesBeans.setReciboanual("");
                temporalInformesPagosMensualesBeans.Agregar();
            }//for

            //anual

             for (int i = 0; i < nanual; i++) {
                //this.idRegimen = String.valueOf(jXTable1.getValueAt(i, 1));
                String tmp;
                tmp = String.valueOf(jXTableAnual.getValueAt(i, 1));
                if (tmp != null) {
                    temporalInformesPagosMensualesBeans.setRegimen(tmp);
                }
                tmp = String.valueOf(jXTableAnual.getValueAt(i, 2));
                if (tmp != null) {
                    temporalInformesPagosMensualesBeans.setIdRegimen(tmp);
                }



//enero

                temporalInformesPagosMensualesBeans.setEnero("");
                temporalInformesPagosMensualesBeans.setFebrero("");
                temporalInformesPagosMensualesBeans.setMarzo("");
                temporalInformesPagosMensualesBeans.setAbril("");
                temporalInformesPagosMensualesBeans.setMayo("");
                temporalInformesPagosMensualesBeans.setJunio("");
                temporalInformesPagosMensualesBeans.setJulio("");
                temporalInformesPagosMensualesBeans.setAgosto("");
                temporalInformesPagosMensualesBeans.setSeptiembre("");
                temporalInformesPagosMensualesBeans.setOctubre("");
                temporalInformesPagosMensualesBeans.setNoviembre("");
                temporalInformesPagosMensualesBeans.setDiciembre("");
                tmp = jTextFieldIdComercio.getText();

                temporalInformesPagosMensualesBeans.setId(tmp);

                temporalInformesPagosMensualesBeans.setTipoId("comercios");
                tmp = jTextFieldComercio.getText();
                temporalInformesPagosMensualesBeans.setPropietario(tmp);
                temporalInformesPagosMensualesBeans.setPeriodopago("Recibo Anual:");
                 temporalInformesPagosMensualesBeans.setReciboanual( (String.valueOf(jXTableAnual.getValueAt(i, 3))));
                temporalInformesPagosMensualesBeans.Agregar();
            }//for
            sesion.con.close();


            reportSource = sesion.getRutaReportes() + "TarjetaPago.jrxml";
            ImprimirRecibo();



        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Boton Mensual()\n " + ex.getMessage().toString());

        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ComerciosPagosVerFrame().setVisible(true);
            }
        });
    }

     private void ImprimirRecibo() {
        try {


            Map<String, Object> params = new HashMap<String, Object>();


            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            JasperReport jasperReport =
                    JasperCompileManager.compileReport(reportSource);

            String sanio = jTextFieldAnio.getText();
            int anio = 0;
            if (sanio == null || sanio.equals("")) {
                anio = 0;
            } else {
                anio = Integer.parseInt(sanio);
            }
            params.put("P_IDMUNICIPIO", sesion.getIdmunicipio());
            params.put("P_MUNICIPIO", sesion.getMunicipio());
            params.put("P_NOMBREUSUARIO", sesion.getUsuario());
            params.put("P_ANIO", anio);
            params.put("P_TIPO1", "Codigo");
            params.put("P_TIPO2", "Comercio");
            JasperPrint jasperPrint =
                    JasperFillManager.fillReport(
                    jasperReport, params, sesion.con);

            JasperViewer.viewReport(jasperPrint, false);
        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Clase: PagosMensualesBeans.java\nImprimirUnaPagina()\n " + ex.getMessage().toString());
        }
    }
    public void CargarComercios() {
        try {

            if (comerciosBeans.getActivo().equals("no")) {
                JOptionPane.showMessageDialog(this, "Este registro esta inactivo", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            this.jTextFieldIdComercio.setText(comerciosBeans.getIdComercio());
            sesion.setIdComercio(this.jTextFieldIdComercio.getText());
            this.jTextFieldComercio.setText(comerciosBeans.getComercio());
            this.idComercio = this.jTextFieldIdComercio.getText();
            sesion.setId(this.jTextFieldIdComercio.getText());
            repaint();


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Clase: PagosComerciosFijosFrame.java\nCargarComercios()\n " + ex.getMessage().toString());
        }
    }

    private void LimpiarTable() {
        try {
            //limpiar  el jXTable

            boolean control = false;
            while (control == false) {
                int n = jXTableMes.getRowCount();

                if (n <= 0) {
                    control = true;
                } else {
                    modelo.removeRow(0);
                }

            }//while

            control = false;
            while (control == false) {
                int n = jXTableAnual.getRowCount();

                if (n <= 0) {
                    control = true;
                } else {
                    modelo2.removeRow(0);
                }

            }//while


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error ", "Clase: PagosComerciosFijosFrame.java\nLimpiarTable()\n " + ex.getMessage().toString());
        }
    }

    public void CargarImpuestos() {
        try {
            LimpiarTable();
            String sAnio = jTextFieldAnio.getText();
            if (sAnio == null || sAnio.equals("") || sAnio.equals("0")) {
                sesion.MostrarMensajeAdvertencia("Mensaje", "Indique el año a mostrar los pagos");
            }
            this.Anio = Integer.parseInt(sAnio);
            idComercio = jTextFieldIdComercio.getText();
            this.sql = "select pagosmensuales.*, regimen.regimen " +
                    "from pagosmensuales, regimen " +
                    " where pagosmensuales.idmunicipio ='" + sesion.getIdmunicipio() + "'" +
                    " and  pagosmensuales.id ='" + this.idComercio + "'" +
                    " and  pagosmensuales.tipoid ='comercios'" +
                    " and  pagosmensuales.anio='" + this.Anio + "'" +
                    " and  pagosmensuales.idmunicipio = regimen.idmunicipio " +
                    " and  pagosmensuales.idregimen = regimen.idregimen  " +
                    " and regimen.activo='si' order by idregimen,anio,numeromes";



            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            PreparedStatement psquery = sesion.con.prepareStatement(sql);
            ResultSet rs = psquery.executeQuery();



// Bucle para cada resultado en la consulta
            int contador = -1;
            int nmes = 0;
            String ene = "", feb = "", mar = "", abr = "", may = "", jun = "", jul = "", ago = "", sep = "", oct = "", nov = "", dic = "";
            while (rs.next()) {
                // Se crea un array que será una de las filas de la tabla.
                contador++;
                Object[] fila = new Object[16]; // Hay tres columnas en la tabla

                fila[0] = rs.getInt("anio");
                fila[1] = rs.getString("regimen");
                fila[2] = rs.getString("idregimen");
                int numeroMes = rs.getInt("numeromes");
                String mes = rs.getString("mes");

                String idRecibo = rs.getString("idrecibo");
                String Pagado = rs.getString("pagado");

                if (idRecibo == null) {
                    idRecibo = "0";
                }
                if (idRecibo.equals("") || idRecibo.equals("0")) {
                    idRecibo = "0";

                }
                if (Pagado.equals("ap")) {
                    idRecibo = "xx";
                }

                switch (numeroMes) {
                    case 0:
                        ene = idRecibo;
                        break;
                    case 1:
                        feb = idRecibo;
                        break;
                    case 2:
                        mar = idRecibo;
                        break;
                    case 3:
                        abr = idRecibo;
                        break;

                    case 4:
                        may = idRecibo;
                        break;
                    case 5:
                        jun = idRecibo;
                        break;
                    case 6:
                        jul = idRecibo;
                        break;
                    case 7:
                        ago = idRecibo;
                        break;
                    case 8:
                        sep = idRecibo;
                        break;
                    case 9:
                        oct = idRecibo;
                        break;
                    case 10:
                        nov = idRecibo;
                        break;
                    case 11:
                        dic = idRecibo;
                        break;
                }


                fila[3] = ene;
                fila[4] = feb;
                fila[5] = mar;
                fila[6] = abr;
                fila[7] = may;
                fila[8] = jun;
                fila[9] = jul;
                fila[10] = ago;
                fila[11] = sep;
                fila[12] = oct;
                fila[13] = nov;
                fila[14] = dic;


                nmes++;
                if (nmes == 12) {
                    nmes = 0;
                    contador = -1;


                    modelo.addRow(fila);

                }


            }
            this.jXTableMes.setModel(modelo);
            jXTableMes.setVisible(true);

            this.jXTableMes.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {
                    if (SwingUtilities.isRightMouseButton(e)) {
//                        popupMenu.show(jXTable1, e.getX(), e.getY());
                    }
                    fila = jXTableMes.rowAtPoint(e.getPoint());
                    int columna = jXTableMes.columnAtPoint(e.getPoint());
                    if ((fila > -1) && (columna > -1)) {
                        String idRegimen = String.valueOf(jXTableMes.getValueAt(fila, 0));
                        String regimen = String.valueOf(jXTableMes.getValueAt(fila, 1));
                        String Svalor = String.valueOf(jXTableMes.getValueAt(fila, 2));
                        Double valor = Double.parseDouble(Svalor);
                        String periodoPago = String.valueOf(jXTableMes.getValueAt(fila, 3));
                        String mesPago = String.valueOf(jXTableMes.getValueAt(fila, 4));
                        sesion.setIdRegimen((idRegimen));

                    }
                }
            });
            TableColumn column = jXTableMes.getColumnModel().getColumn(1);
            column.setPreferredWidth(250);
            sesion.con.close();
            /*
             * Tabla de pagos anuales
             *
             */
            this.sql = "select pagosanuales.*, regimen.regimen " +
                    "from pagosanuales, regimen " +
                    " where pagosanuales.idmunicipio ='" + sesion.getIdmunicipio() + "'" +
                    " and  pagosanuales.id ='" + this.idComercio + "'" +
                    " and  pagosanuales.tipoid ='comercios'" +
                    " and  pagosanuales.anio='" + this.Anio + "'" +
                    " and  pagosanuales.activo ='si' " +
                    " and  pagosanuales.idmunicipio = regimen.idmunicipio " +
                    " and  pagosanuales.idregimen = regimen.idregimen  " +
                    " and regimen.activo='si' order by idregimen,anio";



            if (sesion.Conectar() == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexion", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                return;
            }

            PreparedStatement psquery2 = sesion.con.prepareStatement(sql);
            ResultSet rs2 = psquery2.executeQuery();



// Bucle para cada resultado en la consulta
            contador = -1;


            while (rs2.next()) {
                // Se crea un array que será una de las filas de la tabla.
                contador++;
                Object[] fila2 = new Object[4]; // Hay tres columnas en la tabla

                fila2[0] = rs2.getInt("anio");

                fila2[1] = rs2.getString("regimen");
                fila2[2] = rs2.getString("idregimen");
            
                int numeroMes = rs2.getInt("idrecibo");
                String idRecibo = rs2.getString("idrecibo");
                String Pagado = rs2.getString("pagado");

                if (idRecibo == null) {
                    idRecibo = "0";
                }
                if (idRecibo.equals("") || idRecibo.equals("0")) {
                    idRecibo = "0";

                }
                if (Pagado == null || Pagado.equals("ap")) {
                    idRecibo = "xx";
                }
                fila2[3] = idRecibo;
                modelo2.addRow(fila2);

            }
            this.jXTableAnual.setModel(modelo2);
            jXTableAnual.setVisible(true);


        } catch (Exception ex) {
            sesion.MostrarMensajeError("Error", "ComerciosVerFrame.java\nCargarImpuestos()\n" + ex.getMessage().toString());
        }

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonBuscar;
    private javax.swing.JButton jButtonMostrar;
    private javax.swing.JButton jButtonRegresar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextFieldAnio;
    private javax.swing.JTextField jTextFieldComercio;
    private javax.swing.JTextField jTextFieldIdComercio;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXTable jXTableAnual;
    private org.jdesktop.swingx.JXTable jXTableMes;
    // End of variables declaration//GEN-END:variables
}
